using System.Text;
using System.Web.UI;
/// <summary>
/// Summary description for ScriptManager
/// </summary>
public class ScriptManager
{
    public ScriptManager()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public static void AddShowHideCheckBoxElement(Page page)
    {
        StringBuilder script = new StringBuilder();
        script.Append("function ShowHideElement(CheckBoxID,elementId)\r\n");
        script.Append("{\r\n");
        script.Append(" if (document.getElementById(CheckBoxID).checked == true)\r\n");
        script.Append(" {\r\n");
        script.Append("  document.getElementById(elementId).style.display  = '';\r\n");
        script.Append(" } else {\r\n");
        script.Append("  document.getElementById(elementId).style.display  = 'none';\r\n");
        script.Append(" }\r\n");
        script.Append("}\r\n\r\n");
        page.RegisterClientScriptBlock("ShowHideElement", "<script>" + script.ToString() + "</script>");
    }

    public static void AddCheckKeyCode(Page page)
    {
        StringBuilder script = new StringBuilder();
        script.Append("function CheckKeyCode()\r\n");
        script.Append("{\r\n");
        script.Append(" if(\r\n");
        script.Append("  (event.keyCode == 8 || event.keyCode == 46 || event.keyCode == 35 || event.keyCode == 36) ||\r\n");
        script.Append("  (event.keyCode == 189 || event.keyCode == 109) ||\r\n");
        script.Append("  (event.keyCode >= 48 && event.keyCode <= 57) ||\r\n");
        script.Append("  (event.keyCode >= 96 && event.keyCode <= 105) )\r\n");
        script.Append(" {\r\n");
        script.Append("  return true;\r\n");
        script.Append(" } else {\r\n");
        script.Append("  return false;\r\n");
        script.Append(" }\r\n");
        script.Append("}\r\n");
        page.RegisterClientScriptBlock("CheckKeyCode", "<script>" + script.ToString() + "</script>");
    }

    public static void AddShowHideDependents(Page page)
    {
        StringBuilder script = new StringBuilder();
        script.Append("var groups = new Array();\r\n");

        script.Append("function addToGroup(group, id){\r\n");
        script.Append(" if(groups[group]==null){ groups[group] = new Array();}\r\n");
        script.Append(" groups[group].push(document.getElementById(id));\r\n");
        script.Append("}\r\n");

        script.Append("function ShowDependents(group, value){\r\n");
        script.Append(" if(groups[group]!=null){\r\n");
        script.Append("  for(i =0; i < groups[group].length; i++){ groups[group][i].style.display = ( value.toLowerCase()=='yes' ? '' : 'none' );}; \r\n");

        script.Append(" } \r\n");
        script.Append("}");

        page.RegisterClientScriptBlock("ShowHideDependents", "<script>" + script.ToString() + "</script>");
    }

}
